package demo;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86185
 * Date: 2023-05-18
 * Time: 19:33
 */
public class Test {
    public static void reflectPrivateConstructor() {
        try {
            Class<?> c1 = Class.forName("demo.TestEnum");
            Constructor<?> constructor = c1.getDeclaredConstructor(String.class, int.class, String.class, double.class);
            constructor.setAccessible(true);
            TestEnum testEnum = (TestEnum) constructor.newInstance("123", 8, "lsl", 2.6);
            System.out.println(testEnum);
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        } catch (NoSuchMethodException e) {
            throw new RuntimeException(e);
        } catch (InvocationTargetException e) {
            throw new RuntimeException(e);
        } catch (InstantiationException e) {
            throw new RuntimeException(e);
        } catch (IllegalAccessException e) {
            throw new RuntimeException(e);
        }
    }
    public static void main(String[] args) {
        reflectPrivateConstructor();//枚举被反射过滤了
    }
}
